$(function(){
    // 初始化公告列表
    let Pr_infoList = new Promise( ( resolve, reject ) => {
        $.ajax({
            url: '/manage/announcemen/search_announcemenn.do',
            type: 'post',
            data: {
                name: oPageInfo.searchInfo,
                pageNum: oPageInfo.pageNum,
                pageSize: oPageInfo.pageSize,
                time_sort: oPageInfo.time_sort
            },
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            success: function (data) {
                if (data.status == 0) {
                    resolve(data);
                } else if (data.status == 10) {
                    reject(data);
                } else {
                    reject(data);
                }
            }
        })
    });
    let Pr_barList = new Promise( (resolve,reject)=>{
        $.ajax({
            url: '/manage/projectDetails/index_count.do',
            type: 'post',
            data: {},
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            success: function (data) {
                if (data.status == 0) {
                    resolve(data);
                } else if (data.status == 10) {
                    reject(data);
                } else {
                    reject(data);
                }
            }
        })
    });
    let arrPr = Promise.all( [ Pr_infoList, Pr_barList ] );
    arrPr.then( (data)=>{
        let listData = data[0].data.list;
        let barData = data[1].data;

        To_ADlist( listData );
        To_barList( barData );
    }).catch( (data)=>{
        if(data.status == 10){
            spop_waring(data.msg, function () {}, outLogin);
        }else{
            spop_waring(data.msg );
        }
    });

    // 消息列表绑定事件
    $('#indexInfoList').on('click','a',function(ev){
        ev.preventDefault();

        let searchID = $(this).attr('href');
        window.location.href = '../noticeBoard.html?' + searchID;
    });

    // 渲染信息 -ok
    function To_ADlist( aData ) {
        let ADbox = $('#indexInfoList');
        ADbox.html('');
        aData.forEach( (item,idx)=>{
            $('<a href="annno='+ item.annno +'" class="list-group-item">'+ item.annid +
                '<span>'+ item.creattime +'</span>' +
                '</a>').appendTo( ADbox );
        } );
    }

    // bar 信息
    function To_barList (oData){
        for(let key in oData ){
            console.log(oData[key]);
            let DOM = $('<div>' +
              '            <div>' +
              '               <h3>'+oData[key]+'</h3>' +
              '               <p>'+key+'</p>' +
              '            </div>'+
              '          </div>');

            $('#indexBox').append( DOM );

        }
    }
});